package cn.kgc.ssm.controller;

import cn.kgc.ssm.dto.MessagePageDTO;
import cn.kgc.ssm.entity.Message;
import cn.kgc.ssm.response.ResponseResult;
import cn.kgc.ssm.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author 课工场
 * @date 2024/11/19
 * @description
 */
@RestController
@RequestMapping("message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @GetMapping("page")
    public ResponseResult  messagePage(MessagePageDTO messagePageDTO){

       return messageService.messagePage(messagePageDTO);
    }


    @GetMapping("delete")
    public ResponseResult  deleteMessages(Integer[] ids){
        List<Integer> listIds = Arrays.asList(ids);
        return messageService.delete(listIds) ;
    }

    @PostMapping("edit/{id}")
    public ResponseResult  editMessage(@PathVariable("id") Integer id){
        return messageService.editMessage(id) ;
    }

    @PostMapping("publish")
    public ResponseResult  publishMessage(Message message,@SessionAttribute("memberName") String memberName,@SessionAttribute("tel") String tel){

        message.setTel(tel);
        message.setMemberName(memberName);

        return messageService.publishMessage(message) ;
    }



}
